# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ftgl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=2.1.3-rc5
pkgver=${_pkgver/-/}
pkgrel=2
pkgdesc="OpenGL library to use arbitrary fonts (mingw-w64)"
arch=('any')
url="https://sourceforge.net/p/ftgl/wiki/Home/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cppunit"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-freetype")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${_pkgver}.tar.bz2"
        m4.gl.m4.patch)
sha256sums=('521ff7bd62c459ff5372e269c223e2a6107a6a99a36afdc2ae634a973af70c59'
            '5129d34ca4eccad359a28fc2912e216449821a66fd36f8136896ef8af1a84d3b')

prepare () {
  cd "${srcdir}/${_realname}-${_pkgver/-/\~}"
  sed -i "s|SUBDIRS = src test demo docs|SUBDIRS = src|g" Makefile.am
  patch -p0 -i "${srcdir}"/m4.gl.m4.patch
  autoreconf -vfi
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../"${_realname}-${_pkgver/-/\~}"/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --without-x
  make ECHO=echo
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make ECHO=echo DESTDIR="${pkgdir}" install

  # FS#23283: install missing headers for OpenCascade
  install -m644 $srcdir/"${_realname}-${_pkgver/-/\~}"/src/FT{Face,Library,Size}.h "${pkgdir}${MINGW_PREFIX}/include/FTGL/"

  install -Dm644 $srcdir/"${_realname}-${_pkgver/-/\~}"/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
